//
//  XOWMLoginView.m
//  XOWMSDK
//
//  Created by skyline on 2018/7/25.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "XOWMLoginView.h"
@interface XOWMLoginView()<YJDTextFieldDelegate>
@property (nonatomic, strong) UITableView *tableView;
@end
@implementation XOWMLoginView
- (instancetype)init
{
    self = [super init];
    if (self)
    {
        //        self.cancelBtn.title = @"取消";
        //        [self setValue:helperManager().getPara().color forKeyPath:@"_cancelBtn.titleLBL.textColor"];
    }
    return self;
}

- (XOWMButton *)titleIMG
{
    if (!_titleIMG)
    {
        _titleIMG = [[XOWMButton alloc] init];
        _titleIMG.height = TITLE_HEIGHT;
        _titleIMG.userInteractionEnabled = NO;
        _titleIMG.style = YJDButtonTitleStyleCameo;
        [self addSubview:_titleIMG];
        _titleIMG.c_centerX.equal(self);
        _titleIMG.c_size.equal(CGSizeMake(70, TITLE_HEIGHT));
        _titleIMG.c_centerY.equal(self.backBtn);
    }
    return _titleIMG;
}

- (XOWMLabel *)tipsLBL
{
    if (!_tipsLBL)
    {
        _tipsLBL = [[XOWMLabel alloc] initWithTextColor:RGBA(107, 107, 107, 1.0) font:[UIFont systemFontOfSize:12 weight:UIFontWeightLight]];
        _tipsLBL.textAlignment = NSTextAlignmentLeft;
        [self addSubview:_tipsLBL];
        _tipsLBL.c_centerX.equal(self);
        if (helperManager().getPara().style == XOWMPlatformStyleDefault)
            _tipsLBL.c_top.equal(self.titleIMG.c_bottom).with.coffset(GAP * 1.5);
        else if (helperManager().getPara().style == XOWMPlatformStyleImage)
            _tipsLBL.c_top.equal(self.titleIMG.c_bottom).with.coffset(GAP * 1.0);
    }
    return _tipsLBL;
}

- (XOWMTextField *)nameTF
{
    if (!_nameTF)
    {
        _nameTF = [[XOWMTextField alloc] init];
        _nameTF.type = YJDTextFieldTypeAccountList;
        _nameTF.customDelegate = self;
        _nameTF.returnKeyType = UIReturnKeyNext;
        [self addSubview:_nameTF];
        _nameTF.c_centerX.equal(self);
        _nameTF.c_size.equal(CGSizeMake(self.bounds.size.width - GAP * 2, TEXTFILDHEIGHT));
        if (helperManager().getPara().style == XOWMPlatformStyleDefault)
            _nameTF.c_top.equal(self.tipsLBL.c_bottom).with.coffset(GAP / 2);
        else
            _nameTF.c_top.equal(self.tipsLBL.c_bottom).with.coffset(GAP);
    }
    return _nameTF;
}


- (XOWMTextField *)passTF
{
    if (!_passTF)
    {
        _passTF = [[XOWMTextField alloc] init];
        _passTF.type = YJDTextFieldTypePassword;
        [self addSubview:_passTF];
        _passTF.c_top.equal(self.nameTF.c_bottom).with.coffset(GAP);
        _passTF.c_centerX.equal(self);
        _passTF.c_size.equal(CGSizeMake(self.bounds.size.width - GAP * 2, TEXTFILDHEIGHT));
    }
    return _passTF;
}

- (XOWMButton *)enterBtn
{
    if (!_enterBtn)
    {
        _enterBtn= [[XOWMButton alloc] init];
        _enterBtn.height = BUTTONHEIGHT;
        [_enterBtn addTarget:self action:@selector(yjd_actionForEnterButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_enterBtn];
        _enterBtn.c_left.equal(self).with.coffset(GAP);
        _enterBtn.c_top.equal(self.passTF.c_bottom).with.coffset(1.5 * GAP);
        _enterBtn.c_size.equal(CGSizeMake(self.bounds.size.width - GAP * 2.0, BUTTONHEIGHT));
    }
    return _enterBtn;
}

- (XOWMButton *)leftBtn
{
    if (!_leftBtn)
    {
        _leftBtn= [[XOWMButton alloc] init];
        _leftBtn.height = 20;
        _leftBtn.style = YJDButtonTitleStyleCameo;
        [_leftBtn setValue:[UIFont systemFontOfSize:13 weight:UIFontWeightLight] forKeyPath:@"_titleLBL.font"];
        [_leftBtn addTarget:self action:@selector(yjd_actionForLeftButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_leftBtn];
        if (helperManager().getPara().style == XOWMPlatformStyleImage)
        {
            _leftBtn.c_right.equal(self).with.coffset(-GAP);
            _leftBtn.c_top.equal(self.enterBtn);
        }
        else
        {
            _leftBtn.c_top.equal(self.enterBtn.c_bottom).with.coffset(GAP);
            _leftBtn.c_left.equal(self).with.coffset(GAP);
        }
    }
    return _leftBtn;
}

- (XOWMButton *)rightBtn
{
    if (!_rightBtn)
    {
        _rightBtn= [[XOWMButton alloc] init];
        _rightBtn.height = 20;
        _rightBtn.style = YJDButtonTitleStyleCameo;
        [_rightBtn setValue:[UIFont systemFontOfSize:13 weight:UIFontWeightLight] forKeyPath:@"_titleLBL.font"];
        [_rightBtn addTarget:self action:@selector(yjd_actionForRightButton:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_rightBtn];
        _rightBtn.c_right.equal(self).with.coffset(-GAP);
        if (helperManager().getPara().style == XOWMPlatformStyleImage)
            _rightBtn.c_bottom.equal(self).with.coffset(-GAP * 1.0);
        else
            _rightBtn.c_top.equal(self.enterBtn.c_bottom).with.coffset(GAP);
    }
    return _rightBtn;
}

- (XOWMButton *)cancelBtn
{
    if (!_cancelBtn)
    {
        _cancelBtn = [[XOWMButton alloc] init];
        _cancelBtn.style = YJDButtonTitleStyleCameo;
        _cancelBtn.height = (helperManager().getPara().style == XOWMPlatformStyleImage)?TITLE_HEIGHT:TITLE_HEIGHT * 1.5;
        [_cancelBtn setValue:[UIFont systemFontOfSize:15.0 weight:UIFontWeightLight] forKeyPath:@"_titleLBL.font"];
        [_cancelBtn addTarget:self action:@selector(yjd_actionForCancelButton) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_cancelBtn];
        _cancelBtn.c_centerY.equal(self.titleIMG);
        if (helperManager().getPara().style == XOWMPlatformStyleDefault)
        _cancelBtn.c_right.equal(self).with.coffset(-GAP / 2.0);
        else
            _cancelBtn.c_right.equal(self);
    }
    return _cancelBtn;
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
        _tableView.delegate = self.delegate;
        _tableView.dataSource = self.delegate;
        [self addSubview:_tableView];
        _tableView.c_top.equal(self.nameTF.c_bottom).with.coffset(-3);
        _tableView.c_right.equal(self.nameTF);
        _tableView.c_left.equal(self.nameTF).with.coffset(42);
        _tableView.c_height.equal(0);
    }
    return _tableView;
}

- (void)yjd_actionForEnterButton:(XOWMCustomButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_YJDLoginViewWithEvent:dict:)])
    {
        NSLog(@"====yjd_actionForEnterButton====222");
        [self.delegate yjd_YJDLoginViewWithEvent:YJDLoginViewEventLogin dict:@{@"name":self.nameTF.text,@"password":self.passTF.text}];
    }
}

- (void)yjd_actionForLeftButton:(XOWMCustomButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_YJDLoginViewWithEvent:dict:)])
    {
        [self.delegate yjd_YJDLoginViewWithEvent:YJDLoginViewEventRegister dict:nil];
    }
}

- (void)yjd_actionForRightButton:(XOWMCustomButton *)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_YJDLoginViewWithEvent:dict:)])
    {
        [self.delegate yjd_YJDLoginViewWithEvent:YJDLoginViewEventForgetPWD dict:nil];
    }
}

- (void)yjd_actionForCancelButton
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(yjd_YJDLoginViewWithEvent:dict:)])
    {
        [self.delegate yjd_YJDLoginViewWithEvent:YJDLoginViewEventCancel dict:nil];
    }
}

#pragma mark - YJDTextFieldDelegate
- (void)yjd_actionForXiaLa:(BOOL)isXiaLa
{
    self.tableView.hidden = !isXiaLa;
    if (self.tableView.hidden == NO)
    {
        [self.tableView reloadData];
    }
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField.returnKeyType == UIReturnKeyNext)
    {
        [self.nameTF resignFirstResponder];
        [self.passTF becomeFirstResponder];
        return NO;
    }
    return YES;
}
//#pragma mark - YJDTextFieldDelegate

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */


- (void)sp_checkUserInfo:(NSString *)followCount {
    NSLog(@"Continue");
}
@end
